package com.wgt.observer.java_impl;

import java.util.Observable;

/**
 * Created by wgt on 2017/6/18.
 */
public class ConCreatWeatherSubject extends Observable {


    private String name;
    private Integer age;
    private Double  salary;

    /**
     * 内容更新方法
     * @param content
     */
    public void isChange(String content){
        if (this.name==null||"".equals(this.name.trim())){
            throw new NullPointerException("name is null");
        }
        if (this.age==null||this.age<0){
            throw new NullPointerException("Fields 'age' is wrong!");
        }
        if(this.salary==null||this.salary<0){
            setSalary(0d);
        }


        this.setChanged();

        //推方法
        this.notifyObservers(content);
        //拉方法
        //this.notifyObservers();
    }



    public ConCreatWeatherSubject(String name, Integer age, Double salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Double getSalary() {
        return salary;
    }

    public void setSalary(Double salary) {
        this.salary = salary;
    }


    @Override
    public String toString() {
        return "ConCreatWeatherSubject{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }
}
